package com.ggh.jinjilive.ui.mine.setting;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.BarUtils;
import com.ggh.jinjilive.R;
import com.ggh.jinjilive.common.MerchantSession;
import com.ggh.jinjilive.databinding.ActivitySettingBinding;
import com.ggh.jinjilive.dialog.LiveOccludeDialog;
import com.ggh.jinjilive.dialog.LivePromptDialog;
import com.ggh.jinjilive.listener.AddItemOnClickListener;
import com.ggh.jinjilive.ui.BaseActivity;
import com.ggh.jinjilive.ui.login.LoginActivity;
import com.ggh.jinjilive.utils.ARouterUtils;
import com.ggh.jinjilive.utils.loginIMUtils;
import com.gyf.immersionbar.ImmersionBar;
import com.tencent.imsdk.v2.V2TIMCallback;


/**
 * 设置
 */
@Route(path = ARouterUtils.SettingActivity)
public class SettingActivity extends BaseActivity<ActivitySettingBinding> implements View.OnClickListener {

    //提示弹框
    private LivePromptDialog livePromptDialog;
    @Override
    public void initCreate() {
        super.initCreate();
        ImmersionBar.with(this).keyboardEnable(true).init();
    }

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_setting;

    }

    @Override
    public void initView() {
        super.initView();
        //店铺名称
        setWhiteActionBarStyle("设置",true,true);
        //获取状态栏高度
        binding.llSpacing.setPadding(0, BarUtils.getStatusBarHeight(),0,0);
    }


    @Override
    public void initData() {
        super.initData();
        //提示弹框
        livePromptDialog = new LivePromptDialog(mContext);
        //获取 App 版本号
        binding.tvVersion.setText(AppUtils.getAppVersionName());
    }

    @Override
    public void initViewObservable() {
        super.initViewObservable();
        //收货地址
        binding.setDeliveryAddress.setOnClickListener(this);
        //社区公约
        binding.llMineSetting1.setOnClickListener(this);
        //隐私政策
        binding.llMineSetting2.setOnClickListener(this);
        //服务条例
        binding.llMineSetting3.setOnClickListener(this);
        //联系我们
        binding.llMineSetting4.setOnClickListener(this);
        //主播协议
        binding.llMineSetting5.setOnClickListener(this);
        //意见反馈
        binding.llMineSetting6.setOnClickListener(this);
        //修改密码
        binding.llMineSetting7.setOnClickListener(this);
        //清理缓存
        binding.llMineSetting8.setOnClickListener(this);
        //法律法规
        binding.llMineSetting10.setOnClickListener(this);
        //市场规范
        binding.llMineSetting11.setOnClickListener(this);
        //开店入驻协议
        binding.llMineSetting12.setOnClickListener(this);
        //注销
        binding.outloginMineSetting.setOnClickListener(this);



    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.setDeliveryAddress://收货地址

                break;
            case R.id.ll_mine_setting_1://社区公约
                ARouter.getInstance().build(ARouterUtils.TextActivity)
                        .withString("title","社区公约")
                        .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                        .navigation();
                break;
            case R.id.ll_mine_setting_2://隐私政策
                ARouter.getInstance().build(ARouterUtils.TextActivity)
                        .withString("title","隐私政策")
                        .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                        .navigation();
                break;
            case R.id.ll_mine_setting_3://服务条例
                ARouter.getInstance().build(ARouterUtils.TextActivity)
                        .withString("title","服务条例")
                        .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                        .navigation();
                break;
            case R.id.ll_mine_setting_4://联系我们
                ARouter.getInstance().build(ARouterUtils.TextActivity)
                        .withString("title","联系我们")
                        .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                        .navigation();
                break;
            case R.id.ll_mine_setting_5://主播协议
                ARouter.getInstance().build(ARouterUtils.TextActivity)
                        .withString("title","主播协议")
                        .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                        .navigation();
                break;
            case R.id.ll_mine_setting_6://意见反馈
                break;
            case R.id.ll_mine_setting_7://修改密码
                break;
            case R.id.ll_mine_setting_8://清理缓存
                break;
            case R.id.ll_mine_setting_10://法律法规
                ARouter.getInstance().build(ARouterUtils.TextActivity)
                        .withString("title","法律法规")
                        .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                        .navigation();
                break;
            case R.id.ll_mine_setting_11://市场规范
                ARouter.getInstance().build(ARouterUtils.TextActivity)
                        .withString("title","市场规范")
                        .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                        .navigation();
                break;
            case R.id.ll_mine_setting_12://开店入驻协议
                ARouter.getInstance().build(ARouterUtils.TextActivity)
                        .withString("title","开店入驻协议")
                        .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                        .navigation();
                break;
            case R.id.outlogin_mine_setting://注销
                if(null != livePromptDialog && !livePromptDialog.isShowing()){
                    livePromptDialog.show();
                    livePromptDialog.setTitle("确认退出登录？");
                    livePromptDialog.setAddItemOnClickListener(new AddItemOnClickListener() {
                        @Override
                        public void onSkipClicked(int position, Object mObject) {
                            if(position == 0){
                                livePromptDialog.dismiss();
                            }else if(position == 1){
                                loginIMUtils.logout(new V2TIMCallback() {
                                    @Override
                                    public void onSuccess() {
                                        //清理Token
                                        MerchantSession.getInstance().setToken("");
                                        //标记登录成功
                                        MerchantSession.getInstance().setIsLogin(false);
                                        Intent intent =new Intent(mContext, LoginActivity.class);
                                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                        intent.putExtra("wherever",true);
                                        startActivity(intent);//启动Activity
                                    }

                                    @Override
                                    public void onError(int code, String desc) {

                                    }
                                });
                            }
                        }
                    });
                }
                break;
        }
    }
}
